package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppRoomPaimai;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 房间排麦
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppRoomPaimaiDao.java
 * @Description TODO
 * @createTime 2021年07月29日 14:44:00
 */
@Repository
public class AppRoomPaimaiDao extends BaseDao<AppRoomPaimai>{

    /**
   * 详情
   * @Param: [id]
   * @return: com.vf.admin.miaodong.entity.AppRoomPaimai
   * @Author: zhouyunyi
   * @Date: 2021/07/29
   * @Time: 14:47
   */
    public AppRoomPaimai get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_paimai  where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoomPaimai.class);
    }

    /**
    * 修改，保存
    * @Param: [haoYou]
    * @return: void
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 14:47
    */
    public void save(AppRoomPaimai haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
    * 删除
    * @Param: [id]
    * @return: void
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 14:48
    */
    public void del(Integer roomid,Integer userid) {
        if (roomid <= 0) {
            return;
        }
        if (userid <= 0) {
            return;
        }
        String sql = " delete  from app_room_paimai  where roomid = ? and userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(roomid);
        paramList.add(userid);
        this.del(sql, paramList);
    }

    /**
    * 根据房间id，用户id查询
    * @Param: [roomid, userid]
    * @return: com.vf.admin.miaodong.entity.AppRoomPaimai
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 14:50
    */
    public AppRoomPaimai getRoom(Integer roomid,Integer userid) {
        if (StringEx.isNullOrLing(roomid)) {
            return null;
        }
        if(StringEx.isNull(userid)){
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_paimai  where 1=1");
        sbStr.append(" and roomid = ? ");
        paramList.add(roomid);
        sbStr.append(" and userid = ? ");
        paramList.add(userid);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoomPaimai.class);
    }

    /**
    * 修改上麦状态
    * @Param: [id, state]
    * @return: void
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 15:14
    */
    public void updateState(Integer id,Integer state){
        if(StringEx.isNull(id)){
            return;
        }
        if(StringEx.isNull(state)){
            return;
        }
        String sql = " UPDATE app_room_paimai SET state = ? WHERE id = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(state);
        paramList.add(id);
        this.update(sql,paramList);
    }

    /**
    * 房间排麦列表
    * @Param: [map, splitPageBean]
    * @return: java.util.List<com.vf.admin.miaodong.entity.AppRoomPaimai>
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 15:23
    */
    public List<AppRoomPaimai> list(Map<String,Object> map, SplitPageBean splitPageBean){
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT * FROM app_room_paimai  WHERE 1=1 ");
        if(StringEx.isNotNull(map.get("roomid"))){
            sbStr.append(" and roomid = ? ");
            paramList.add(map.get("roomid"));
        }
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppRoomPaimai.class, splitPageBean);
    }

    /**
    * 更新用户昵称
    * @Param: [userid 用户id, nick 用户昵称]
    * @return: void
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 16:41
    */
    public void updateNick(Integer userid,String nick){
        if(StringEx.isNull(userid)){
            return;
        }
        if(StringEx.isNull(nick)){
            return;
        }
        String sql = " UPDATE app_room_paimai SET nick = ? WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    /**
    * 更新用户头像
    * @Param: [userid 用户id, pic 用户头像]
    * @return: void
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 16:44
    */
    public void updatePic(Integer userid,String pic){
        if(StringEx.isNull(userid)){
            return;
        }
        if(StringEx.isNull(pic)){
            return;
        }
        String sql = " UPDATE app_room_paimai SET pic = ? WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql,paramList);
    }

    /**
    * 更新用户性别
    * @Param: [userid 用户id, sex 用户性别]
    * @return: void
    * @Author: zhouyunyi
    * @Date: 2021/07/29
    * @Time: 16:47
    */
    public void updateSex(Integer userid,Integer sex){
        if(StringEx.isNull(userid)){
            return;
        }
        if(StringEx.isNull(sex)){
            return;
        }
        String sql = " UPDATE app_room_paimai SET sex = ? WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(sex);
        paramList.add(userid);
        this.update(sql,paramList);
    }

}
